package com.teemor.tim.model.message;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.teemor.tim.enums.MessageType;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @ename zhoulk
 * @cname 周李科
 * @date 2020/12/16 14:26
 */
@Data
@NoArgsConstructor
public class MessageModel implements MessageWrapper, Serializable {
    private static final long serialVersionUID = 5856592180913882000L;

    @JSONField(name = "MsgType")
    private String MsgType;

    @JSONField(name = "MsgContent")
    private Message message;

    public MessageModel(TimMessage timMessage, MessageType messageType) {
        this.MsgType = timMessage.getMsgType();
        this.message = JSON.parseObject(JSON.toJSONString(timMessage.getContent()), messageType.messageType);
    }

    public MessageModel(MessageType type, Message message) {
        this.MsgType = type.name();
        this.message = message;
    }
}
